ticketProto = {
    draggable : {
        ddGroup : 'scrumboard'
    }
    ,initComponent : function()
    {
        this.data = this.ticketData;
        ticket.superclass.initComponent.call(this);
        this.updateTicketInfo();
    }
    ,tools:[
        {
            id:'gear',
            qtip: 'Edit ticket',
            handler: function(event, toolEl, panel){
                console.log(event, toolEl, panel);
                Ext.MessageBox.alert('TODO', 'Update given ticket (panel)');
            }
        },{
            id:'help',
            qtip: 'Add comment to ticket',
            handler: function(event, toolEl, panel){
                panel.openCommentPrompt();
            }
        },{
            id:'plus',
            qtip: 'Book working hours',
            handler: function(event, toolEl, panel){
                panel.openBookHoursPrompt();
            }
        }
    ]
    ,ticketData : null
    , setScrumState : function (newState)
    {
        if(newState != this.ticketData.scrumState)
        {
            this.ticketData.scrumState = newState;
            this.updateTicket();
        }
        return true;
    }
    ,updateTicket : function()
    {
        Ext.Ajax.request({
			url:'Ticket/update'
            ,params: this.ticketData
            ,scope: this
            ,failure : sweatShop.globals.formSubmitFailed
            ,success : this.ticketUpdateHandler
		});
    }
    , ticketUpdateHandler: function (response, request) {
        var result = Ext.util.JSON.decode(response.responseText);
        sweatShop.log(result.message, result.success ? 1 : 3);
    }
    , updateTicketInfo: function ()
    {
       this.setTitle([
            '#'
            ,this.ticketData.ticketId
            ,': [',this.ticketData.product,'] '
            ,this.ticketData.name
        ].join(''));
        this.removeClass(this.ticketData.previousCls);
        this.addClass(this.ticketData.colorCls);
    }
    , openBookHoursPrompt : function()
    {
        new usedHoursPrompt({
            ticketID: this.ticketData.ticketId
            ,ticket : this
        }).show();
    }
    , openCommentPrompt : function()
    {
        new ticketCommentPrompt({
            ticketId: this.ticketData.ticketId
            ,ticket : this
        }).show();
    }
    , addBookedHoursToTicket : function(hours)
    {
        this.ticketData.usedTime = parseFloat(this.ticketData.usedTime) + parseFloat(hours);
        this.update(this.ticketData);
    }
    , addCommentToTicket : function(comment)
    {
        if(comment && comment.date && comment.user)
        {
            this.ticketData.comments.unshift(comment);
            this.update(this.ticketData);
        }
    }
};
ticket = Ext.extend(ticketUi, ticketProto);
//ticket.dd = Ext.extend(Ext.dd.DragSource, );
Ext.reg('ticket', ticket);
